from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.interval import IntervalTrigger
from apscheduler.executors.pool import ThreadPoolExecutor
from pitchSrc.pitchOnl.pitchOnl import pitchOnl
from pitchSrc.pitchHis.pitchHis import pitchHis
from common.config import pitchConfig as Config
from pitchSrc.tools.toFile import toPitchUploadCsv
from pitchSrc.tools.pitchExplore import pitchExplore
import time



''' MAIN ##################################################################################
1. 主动探索
2. 历史优化
3. 在线优化（线程池）
'''
if __name__ == "__main__":
    # 主动探索
    # pitchExplore()

    # 历史优化
    # pitchHis()

    # 在线优化
    executors = {
        'default': ThreadPoolExecutor(10)
    }
    main = BackgroundScheduler()
    main.add_job(pitchOnl, IntervalTrigger(seconds=Config.pitchOnlSpan+30), id='pitchOnl')
    main.add_job(toPitchUploadCsv, IntervalTrigger(seconds=Config.pitchUploadSpan), id='toPitchUploadCsv')
    main.start()

    # 防止主程序退出
    while True:
        time.sleep(1000)
